<template>
    <van-sticky>
      <van-nav-bar
        title="编辑地址"
        left-text="返回"
        left-arrow
        @click-left="onClickLeft"
      />
    </van-sticky>
  
    <van-address-edit
      :area-list="areaList"
      show-delete
      show-set-default
      :address-info="info"
      :area-columns-placeholder="['请选择', '请选择', '请选择']"
      @save="onSave"
      @delete="onDel"
    />
  </template>
  
  <script setup>
  import { areaList } from '@vant/area-data';
  const { proxy } = getCurrentInstance();
  
  //返回按键
  const onClickLeft = () => {
    proxy.$router.back();
  };
  
  const onSave = async (values) => {
      let params = {
          busid:proxy.$business.id,
        //   id:addrid.value,
          consignee:values.name,
          mobile:values.tel,
          code:values.areaCode,
          address:values.addressDetail,
          status:values.isDefault === true ? 1 : 0
      }
  
      let result = await proxy.$post({
          url:'/business/address/add',
          params
      })
  
      if(result.code === 1)
      {
          proxy.$NotifySuccess({
              msg:result.msg,
              onClose:() => {
                onClickLeft();
              }
          })
  
          return false;
      }else{
          proxy.$NotifyWarn(result.msg);
  
          return false;
      }
  }
  </script>